package com.example.demo.dao;

import com.example.demo.entity.Cat;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * Created by Choisaaaa on 2018/6/7.
 * @Repository:表名这是一个持久化操作对象
 * 步骤：
 * 1.定义一个sql语句
 * 2.定义一个RowMapper
 * 3.执行查询方法
 */
@Repository
public class CatDao {
    @Resource
    private JdbcTemplate jdbcTemplate;

    public Cat selectByCatName(String catName){
        String sql  = "select * from cat where cat_name=?";
        RowMapper<Cat> rowMapper = new BeanPropertyRowMapper<>(Cat.class);
        Cat cat = jdbcTemplate.queryForObject(sql,new Object[]{catName}, rowMapper);
        return cat;
    }
}
